// DlgAccountEdit.cpp : implementation file
//

#include "stdafx.h" 
#include "GameNetManager.h"
#include "DlgAccountEdit.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgAccountEdit dialog


CDlgAccountEdit::CDlgAccountEdit(CWnd* pParent /*=NULL*/)
: CDialog(CDlgAccountEdit::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgAccountEdit)
	m_strLoginName = _T("");
	m_strLoginPwd = _T("");
	m_iShowType=0; //add
	m_pAcc=NULL;
	//}}AFX_DATA_INIT
}


void CDlgAccountEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgAccountEdit)
	DDX_Control(pDX, IDC_CMB_SERVER, m_cmb_Server);
	DDX_Control(pDX, IDC_CMB_SCRIPT, m_cmb_Script);
	DDX_Text(pDX, IDC_EDIT_LGN_NAME, m_strLoginName);
	DDX_Text(pDX, IDC_EDIT_LOGIN_PWD, m_strLoginPwd);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgAccountEdit, CDialog)
	//{{AFX_MSG_MAP(CDlgAccountEdit)
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgAccountEdit message handlers

BOOL CDlgAccountEdit::OnInitDialog() 
{
	CDialog::OnInitDialog();
	this->ShowInfo();
	return TRUE;  
}

void CDlgAccountEdit::OnDestroy() 
{
	CDialog::OnDestroy();

}

void CDlgAccountEdit::OnOK() 
{
	UpdateData(TRUE);

	CString strTemp=_T("");
	if(m_pAcc==NULL)
	{
		m_pAcc=new Account;
		m_pAcc->m_iAccountID=-1;
	}
	m_pAcc->m_iScriptID=m_cmb_Script.GetCurSel();
	m_pAcc->m_iScriptID=m_cmb_Script.GetItemData(m_pAcc->m_iScriptID);
	m_cmb_Script.GetWindowText(strTemp);
	_tcscpy(m_pAcc->m_tcScriptName,strTemp.GetBuffer(strTemp.GetLength()));
	m_pAcc->m_iServerID=m_cmb_Server.GetCurSel();
	m_pAcc->m_iServerID=m_cmb_Server.GetItemData(m_pAcc->m_iServerID);
	m_cmb_Server.GetWindowText(strTemp);
	_tcscpy(m_pAcc->m_tcServerName,strTemp.GetBuffer(strTemp.GetLength())); 
	_tcscpy(m_pAcc->m_tcLoginName,m_strLoginName.GetBuffer(m_strLoginName.GetLength()));
	_tcscpy(m_pAcc->m_tcLoginPwd,m_strLoginPwd.GetBuffer(m_strLoginPwd.GetLength()));


	//CDBDataManager::CreateInstance()->UpdateAcc(m_pAcc);

	CDialog::OnOK();
}

void CDlgAccountEdit::SetShowType(int iShowType)
{
	this->m_iShowType=iShowType;
}

void CDlgAccountEdit::SetAcc(lpAccount pAcc)
{
	m_pAcc=pAcc;
}

lpAccount CDlgAccountEdit::GetAcc()
{
	return m_pAcc;
}

void CDlgAccountEdit::BoundInfo()
{
	//CDBDataManager::CreateInstance()->BoundServerList(&m_cmb_Server);
	//CDBDataManager::CreateInstance()->BoundScriptList(&m_cmb_Script);
}

void CDlgAccountEdit::ShowInfo()
{ 
	BoundInfo();
	if(m_iShowType==1)
	{
		m_strLoginName=m_pAcc->m_tcLoginName;
		m_strLoginPwd=m_pAcc->m_tcLoginPwd;
		//CDBDataManager::CreateInstance()->SelectCMBItemByData(&m_cmb_Script,m_pAcc->m_iScriptID);
		//CDBDataManager::CreateInstance()->SelectCMBItemByData(&m_cmb_Server,m_pAcc->m_iServerID);
		UpdateData(FALSE);
	}
}